class QueryEntity {
    constructor({
                    houseProvince = '',
                    houseName = '',
                    houseAction = 1,
                    houseOfficer = '',
                    gatewayIp = '',
                    gatewayIpAction = 1,
                    startTime = '',
                    endTime = '',
                    idcId = '',
                    timeArray = [],
                } = {}) {
        this.houseProvince = houseProvince
        this.houseName = houseName
        this.houseAction = houseAction
        this.houseOfficer = houseOfficer
        this.gatewayIp = gatewayIp
        this.gatewayIpAction = gatewayIpAction
        this.startTime = startTime
        this.endTime = endTime
        this.timeArray = timeArray
        this.idcId = idcId
    }
}

const app = new BasicTableVue({
    data: function () {
        return {
            api: baseHouseInfoApi,
            columns: [
                TableColumn.generate({
                    type: 'selection',
                    width: 30,
                    align: 'center',
                }),
                TableColumn.generate({
                    prop: 'id',
                    title: 'ID',
                    align: 'center',
                }),
                TableColumn.generate({
                    prop: 'houseName',
                    title: '机房名称',
                    customComponent: 'true',
                }),
                TableColumn.generate({
                    prop: 'houseNumber',
                    title: '机房编号',
                }),
                TableColumn.generate({
                    prop: 'idcId',
                    title: '经营许可证号',
                    align: 'center',
                }),
                TableColumn.generate({
                    prop: 'houseType',
                    title: '机房性质',
                    formatter: fieldFormatter.facade(fieldFormatter.baseHouseInfo.houseTypeMap),
                }),
                TableColumn.generate({
                    prop: 'provinceName',
                    title: '所在省',
                    sortable: false,
                }),
                TableColumn.generate({
                    prop: 'houseOfficerName',
                    title: '安全责任人',
                    sortable: false,
                    align: 'center',
                }),
                TableColumn.generate({
                    prop: 'sourceCount',
                    title: '资源统计',
                    sortable: false,
                    customComponent: 'true',
                    align: 'center',
                }),
                TableColumn.generate({
                    prop: 'monitorCount',
                    title: '监测统计',
                    sortable: false,
                    customComponent: 'true',
                    align: 'center',
                }),
                TableColumn.generate({
                    prop: 'reportStatus',
                    title: '报备阶段',
                    formatter: fieldFormatter.facade(fieldFormatter.baseData.reportStatusMap),
                    align: 'center',
                }),
                TableColumn.generate({
                    prop: 'updateTime',
                    title: '更新时间',
                    formatter: TableColumn.datetimeFormat,
                    align: 'center',
                }),
                TableColumn.generate({
                    prop: 'operating',
                    title: '操作',
                    sortable: false,
                    customComponent: 'true',
                    align: 'center',
                    width: 100,
                }),
            ],
            provinces: [],
            houseOfficerList: [],
            houseMap: new Map(),
        }
    },
    methods: {
        createForm() {
            return new QueryEntity()
        },
        forwardUpdate(data) {
            forward('/basic-data/modify/admin_house_info_modify', data)
        },
        async init() {
            this.initHouseProvinceData()
            this.initHouseOfficerList()
            this.houseMap = rx.arrayToMap(await baseHouseInfoApi.selectList(), ({id}) => id, ({houseName}) => houseName)
        },
        initHouseProvinceData: async function () {
            this.provinces = await sysConfProvinceApi.selectList()
        },
        async initHouseOfficerList() {
            this.houseOfficerList = await baseHouseOfficerApi.selectList()
        },
        forwardSeePage(data) {
            forward('/basic-data/see/admin_houseinfo_see', data)
        },
        /**
         *默认机房
         */
        async defaultHouse(data) {
            await baseHouseInfoApi.update({
                id: data.id,
                defaultHouse: 1,
            })
        },
        async downloadTemplate() {
            await baseHouseInfoApi.downloadTemplate('机房信息管理导入模板.xlsx')
        },
        forwardUrl(url, data) {
            forward(url, data)
        },
        timeArrayChange(array) {
            [start, end] = array || []
            this.form.startTime = start
            this.form.endTime = end
        },
        async insertReport(id) {
            if (await ajaxOption({
                res: this.api.insertReport(id),
                danger: '新增上报失败',
                success: '新增上报成功',
            })) {
                await this.searchPage()
            }
        },
        async updateReport(id) {
            if (await ajaxOption({
                res: this.api.updateReport(id),
                danger: '修改上报失败',
                success: '修改上报成功',
            })) {
                await this.searchPage()
            }
        },
    },
})
